﻿/* 
 * File:   correct.h
 * Author: aple
 */

#ifndef __CORRECT_H_H_
#define	__CORRECT_H_H_

#include "stdint.h"

#ifdef	__cplusplus
extern "C" {
#endif


	/*-i16类型列表排序*/
	typedef struct
	{
		int16_t sort_val;
		int16_t element_val;
	} str_2e_i16_list_sort_val_type;

	void str_2e_i16_list_sort(str_2e_i16_list_sort_val_type *list, uint8_t len, int16_t min);

	/*-i16类型列表排序*/
	typedef struct
	{
		int32_t sort_val;
		int32_t element_val;
	} str_2e_i32_list_sort_val_type;

	void str_2e_i32_list_sort(str_2e_i32_list_sort_val_type *list, uint8_t len, int32_t min);


	/*-i16类型列表修正*/
	typedef struct
	{
		int16_t i_src;
		int16_t i_offset;
	} correct_i16point_type;

	float i16point_list_correct(correct_i16point_type *list, uint16_t list_len, float fval);

	/*i32类型列表修正*/
	typedef struct
	{
		int32_t i_src;
		int32_t i_offset;
	} correct_i32point_type;

	float i32point_list_correct(correct_i32point_type *list, uint16_t list_len, float fval);


	/*float类型列表修正*/
	typedef struct
	{
		float f_src;
		float f_offset;
	} correct_fpoint_type;

	float fpoint_list_correct(correct_fpoint_type *list, uint16_t list_len, float fval);

	/*数据映射*/
	typedef struct
	{
		int32_t src;
		int32_t des;
	} i32_data_reamap_type;

	typedef struct
	{
		int16_t src;
		int16_t des;
	} i16_data_reamap_type;

	typedef struct
	{
		float src;
		float des;
	} f32_data_reamap_type;

	/*映射表的src值必须按大小顺序排列，接口检测到无递增的src就退出*/
	/*输入数据超出列表范围按照两端的固定值叠加*/
	float dat_remap_i32(i32_data_reamap_type *list, uint16_t list_len, float in_dat);
	float dat_remap_i16(i16_data_reamap_type *list, uint16_t list_len, float in_dat);
	float dat_remap_f32(f32_data_reamap_type *list, uint16_t list_len, float in_dat);

	/*同dat_remap_i16，内部全整数运算，无小数精度*/
	int16_t dat_remap_i16_to_i16(i16_data_reamap_type *list, uint16_t list_len, int16_t in_dat);

	/*超出范围也按照斜率计算*/
	float dat_remap_2p_i32(i32_data_reamap_type p1, i32_data_reamap_type p2, float in_dat);
	float dat_remap_2p_i16(i16_data_reamap_type p1, i16_data_reamap_type p2, float in_dat);
	float dat_remap_2p_f32(f32_data_reamap_type p1, f32_data_reamap_type p2, float in_dat);

	float dat_remap_2pn_i32(int32_t a1, int32_t a2, int32_t b1, int32_t b2, float in_dat);
	float dat_remap_2pn_i16(int16_t a1, int16_t a2, int16_t b1, int16_t b2, float in_dat);
	float dat_remap_2pn_f32(float a1, float a2, float b1, float b2, float in_dat);
	int16_t dat_remap_2pn_i16_toi(int16_t a1, int16_t a2, int16_t b1, int16_t b2, int16_t in_dat);

#ifdef	__cplusplus
}
#endif

#endif	/* __CORRECT_H_H_ */

